#include <iostream>
#include "Network.h"

using namespace std;

char* rtrim(char* buf,int len) {
	while(--len>0) {
		if(buf[len]=='\n') buf[len]='\0';
		else if(buf[len]=='\r') buf[len]='\0';
		else if(buf[len]==' ') buf[len]='\0';
		else if(buf[len]=='\t') buf[len]='\0';
		else break;
	}
	return buf;
}

char* ltrim(char* buf,int len) {
	int p=0;
	while(p<len) {
		if(buf[p]=='\n') buf[p]='\0';
		else if(buf[p]=='\r') buf[p]='\0';
		else if(buf[p]==' ') buf[p]='\0';
		else if(buf[p]=='\t') buf[p]='\0';
		else break;
		p++;
	}
	buf+=p;
	return buf;
}

char* trim(char* buf,int len) {
	buf=rtrim(buf,len);
	return ltrim(buf,len);
}

int main() {
	Network socket;
	socket.createsocket();
	socket.connect("127.0.0.1",5000);
	socket.send("coucou\n");
	char buf[513];
	int len=socket.recv(buf,512);
	cout << rtrim(buf,len) << endl;
	socket.close();
	return EXIT_SUCCESS;
}
